#######################################################################################################################
# Script Name: Orchards_Detection_Attempt8.ipynb
# Purpose: To complete the entire object detection workflow in one script
# Modifications to code and comments by: Shannon England
#
# Note: the original script was obtained from the arcgis-python-api-master folder,downloaded from the website
# https://github.com/Esri/arcgis-python-api
#######################################################################################################################
# showing the path to the imagery used to create the training samples
# this was done using the Export Trianing Samples for Deep Learning tool in ArcGIS Pro
mosaic = r'E:\ShannonE\GDA_Project_SE\Historical_Orthomosaic\Rotated_Mosaic.tif'
mosaic
# connecting to folder containing exported training samples : settings were 750 x 750 pixels with 375 stride in x and y direction
training_data = r'E:\ShannonE\GDA_Project_SE\Historical_Orthomosaic\Attempt8'
training_data
# importing prepare data library from arcgis to apply transformations and enhance the orchards layer
from arcgis.learn import prepare_data
data = prepare_data(training_data, {1: 'Young Orchard',
2: 'Mixed Orchard',
4: 'Overexposed'})
data.show_batch()
# importing the object detection model that will be used
from arcgis.learn import SingleShotDetector
# settings for single shot detector
ssd = SingleShotDetector(data, grids=[2,1])
# finding the optimum learning rate - low learning rate leads to slow training of model
ssd.lr_find()
# showing the model learning the task by showing the loss and validation for the training data
ssd.fit(10, slice(0.001, 0.02))
# visualizing the results of the trained model
ssd.show_results(rows=20, thresh=0.05)
# saving the trained model
ssd.save('OrchardDetector_8')